package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("admin/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 分页查询
     *
     * @param setmealPageQueryDTO
     * @return
     */
    @GetMapping("page")
    public Result findByPage(SetmealPageQueryDTO setmealPageQueryDTO) {
        log.info("分页查询:{}", setmealPageQueryDTO);
        PageResult pageResult = setmealService.findByPage(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增套餐
     *
     * @param setmealDTO
     * @return
     */
    @PostMapping
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO) {
        log.info("新增套餐:{}", setmealDTO);
        setmealService.addSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 套餐起售、停售
     *
     * @param status
     * @param id
     * @return
     */
    @PostMapping("status/{status}")
    public Result updateStatus(@PathVariable Integer status, Integer id) {
        log.info("根据id查询套餐:{},{}", status, id);
        setmealService.updateStatus(status, id);
        return Result.success();
    }

    /**
     * 根据id查询套餐
     *
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Result findById(@PathVariable Integer id) {
        log.info("根据id查询套餐");
        Setmeal setmeal = setmealService.findById(id);
        return Result.success(setmeal);
    }

    /**
     * 批量删除套餐
     *
     * @return
     */
    @DeleteMapping
    public Result deleteSetmeal(@RequestParam List<Integer> ids) {
        log.info("批量删除:{}", ids);
        setmealService.deleteSetmeal(ids);
        return Result.success();
    }

    /**
     * 修改套餐
     *
     * @return
     */
    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO) {
        log.info("修改套餐:{}", setmealDTO);
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }
}
